AC_INIT(fastls, 0.1, [enridis@gmail.com])
AM_INIT_AUTOMAKE(fastls, 0.1)

AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB

AC_HEADER_STDBOOL
AC_CHECK_HEADERS([fcntl.h])

AC_TYPE_INT64_T
AC_TYPE_UINT64_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T

AC_FUNC_MALLOC
AC_CHECK_FUNCS([ftruncate])
AC_CHECK_FUNCS([atexit])
AC_CHECK_FUNCS([memset])
AC_C_INLINE

FLS_BUILD_REVISION=`svnversion $srcdir`
FLS_BUILD_REVISION=${FLS_BUILD_REVISION:-unknown}
AC_DEFINE_UNQUOTED(FLS_BUILD_REVISION, ["$FLS_BUILD_REVISION"], [SVN Revision])
AC_SUBST(FLS_BUILD_REVISION)


CFLAGS="-Wall -pipe"
CXXFLAGS="$CFLAGS"

AC_ARG_WITH(mblock_size,
    [AS_HELP_STRING([--with-mblock_size=size], [use specific mblock size(default=4096)])],
	[mblock_size=$withval], [mblock_size=4096])
AC_DEFINE_UNQUOTED(MBLOCK_DEFAULT_SIZE, [$mblock_size], [MBlock default size.])

AC_ARG_WITH(string_size,
    [AS_HELP_STRING([--with-string_size=size], [use specific max string size(default=4096)])],
	[string_size=$withval], [string_size=4096])
AC_DEFINE_UNQUOTED(MAX_STRING_SIZE, [$string_size], [Maximum size of String class.])

AC_ARG_WITH(indexdb_size,
    [AS_HELP_STRING([--with-indexdb_size=size], [maximum size of IndexDB(default=65536)])],
	[indexdb_size=$withval], [indexdb_size=65536])
AC_DEFINE_UNQUOTED(MAX_INDEXDB_SIZE, [$indexdb_size], [Maximum size per each IndexDB storage.])

AC_ARG_WITH(celldb_cellcount,
    [AS_HELP_STRING([--with-celldb_cellcount=size], [maximum cell count per each CellDB storage(default=65536)])],
	[celldb_cellcount=$withval], [celldb_cellcount=65536])
AC_DEFINE_UNQUOTED(MAX_CELLDB_CELL_COUNT, [$celldb_cellcount], [Maximum cell count per each CellDB storage.])

AC_ARG_WITH(celldb_cellsize,
    [AS_HELP_STRING([--with-celldb_cellsize=size], [maximum cell size per each CellDB block(default=256)])],
	[celldb_cellsize=$withval], [celldb_cellsize=256])
AC_DEFINE_UNQUOTED(MAX_CELLDB_CELL_SIZE, [$celldb_cellsize], [Maximum cell size per each CellDB block.])


AC_ARG_ENABLE(optimized,
    [AS_HELP_STRING([--enable-optimized=yes], [enable optimizing flags for production.)])],
	[ADD_CFLAGS+=" -O3"], [ADD_CFLAGS+=" -O0"])

AC_ARG_ENABLE(debug,
    [AS_HELP_STRING([--enable-debug=yes], [include debug information. Need for debuging.)])],
	[ADD_CFLAGS+=" -g3 -DDEBUG"], [ADD_CFLAGS+=" -g0 -DNDEBUG"])

CFLAGS="$CFLAGS $ADD_CFLAGS"
CXXFLAGS="$CXXFLAGS $ADD_CFLAGS"
AC_SUBST(ADD_CFLAGS)

LIBS=""

AC_ARG_WITH(thread_model,
    [AS_HELP_STRING([--with-thread_model=model], [use specific thread model (default=thr)])],
	[thread_model=$withval], [thread_model=thr])
	
AC_CHECK_FUNC(pthread_create, ,
    [ AC_CHECK_LIB($thread_model, pthread_create, LIBS="$LIBS -l$thread_model",
	AC_MSG_ERROR(*** Cannot find $thread_model library );  exit ) ] )

AC_SUBST(LIBS)

AC_CONFIG_HEADERS(config.h)

AC_OUTPUT(
Makefile
FastDB/Makefile
FileSystem/Makefile
Thread/Makefile
Tools/Makefile
)

